package com.appspot.didit.client.ui;

import com.appspot.didit.client.workitem.ChangesListener;
import com.google.gwt.event.dom.client.MouseOutEvent;
import com.google.gwt.event.dom.client.MouseOutHandler;
import com.google.gwt.event.dom.client.MouseOverEvent;
import com.google.gwt.event.dom.client.MouseOverHandler;
import com.google.gwt.user.client.ui.Label;

public class LabelWithLink extends Label {
	
	int state = 0;
	int mouseIn = 0;
	ChangesListener cl;
	
	public LabelWithLink(String text, int size) {
		super(text);
		setStylePrimaryName("tags");
		
		this.getElement().getStyle().setProperty("fontSize", size+"pt");
		this.getElement().getStyle().setProperty("color", "#306EFF");
		addMouseOverHandler(new MouseOverHandler() {
			public void onMouseOver(MouseOverEvent event) {
				mouseIn = 1;
				updateStyle();
			}
	    });
		addMouseOutHandler(new MouseOutHandler() {
			public void onMouseOut(MouseOutEvent event) {
				mouseIn = 0;
				updateStyle();
			}
	    });
	}
	
	public void setFontSize(int size) {
		this.getElement().getStyle().setProperty("fontSize", size+"pt");
	}
	/*protected void updateStyle() {
		setStyleName("tag" + tag + "_" + state + "_" + mouseover);
	}*/
	
	protected void updateStyle() {
		String underline = "";
		if(mouseIn == 1) {
			underline = "underline";
		}
		this.getElement().getStyle().setProperty("textDecoration", underline);
		
		String color = "";
		if(state == 1) {
			color = "#808080";
		} else {
			color = "#306EFF";//"000000";
		}
		this.getElement().getStyle().setProperty("color", color);
		
	}
	
	/*public LabelWithLink(String text, int t, int s) {
		super(text);
		this.tag = t;
		this.state = s;
		
		setStylePrimaryName("tag" + tag + "_" + state + "_" + mouseover);
		addMouseOverHandler(new MouseOverHandler() {
			public void onMouseOver(MouseOverEvent event) {
				// TODO Auto-generated method stub
				mouseover = 1;
				updateStyle();
				System.out.println("in");
			}
	    });
		addMouseOutHandler(new MouseOutHandler() {
			public void onMouseOut(MouseOutEvent event) {
				// TODO Auto-generated method stub
				mouseover = 0;
				updateStyle();
			}
	    });
		
		addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				state = (state + 1) % 2;
				updateStyle();
				//cl.update();
			}
	    });
	}
	
	protected void updateStyle() {
		setStyleName("tag" + tag + "_" + state + "_" + mouseover);
	}*/
	
	public int getState() {
		return state;
	}

	public void setState(int state) {
		this.state = state;
		updateStyle();
	}

	public ChangesListener getListener() {
		return cl;
	}

	public void setListener(ChangesListener cl) {
		this.cl = cl;
	}
}
